<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>

	<!--引入jquery-->
	<script src="${pageContext.request.contextPath}/js/jquery-3.3.1.js" type="text/javascript" charset="utf-8"></script>
	<!--引入bootsrap-->
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
	<script src="${pageContext.request.contextPath}/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
	
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/user/index.css"/>
	
	<script type="text/javascript">
			$(function () {
				//发送ajax，请求商品分类数据
				$.post(
					"${pageContext.request.contextPath}/TypeServlet?action=queryAll",//url
					//data-json格式数据
					function (types) {//callback
						$.each(
							types,
							function(index) {
								var tName = types[index].tName;
								var typeId = types[index].typeId;
								//动态创建子元素
								var url = "${pageContext.request.contextPath}/RoomServlet?action=queryByType&typeId=" + typeId;
								var $aEle = "<a href='" + url + "'>" + tName + "</a>";
								var $Li = $("<li>"+ $aEle +"</li>");
								//获得父元素
								var $UL = $("#typesUl");
								//添加阶段
								$UL.append($Li);
							}
						);
					},
					"json"
				);
			});
	</script>
</head>
<body>

	<nav class="navbar navbar-inverse">
	  	<div class="container">
		    <div class="navbar-header">		      
		       <a class="navbar-brand logo" href="${pageContext.request.contextPath }">Castle Hotel</a>
		    </div>
		    
		    <!--分类列表-->
			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
			    <ul class="nav navbar-nav" id="typesUl">
			    </ul>
			
				<!--搜索框-->
				<form class="navbar-form navbar-left" method="post"
					action="${pageContext.request.contextPath }/RoomServlet?action=queryByName">
		        	<div class="form-group">
		          		<input type="text" class="form-control" name="rname" placeholder="请输入商品名称">
		        	</div>
		        	<button type="submit" class="btn btn-default">搜索</button>
		      	</form>
     
     				<!--登录注册-->
		      	<ul class="nav navbar-nav navbar-right">
		      	
		      		<c:if test="${empty user }">
			      		<li><a href="${pageContext.request.contextPath }/UserServlet?action=loginUi">登录</a></li>
			        	<li><a href="${pageContext.request.contextPath }/UserServlet?action=registUi">注册</a></li>
		      		</c:if>
		      		<c:if test="${not empty user }">
		      			<li><h5 style="color:white ;padding:6px">欢迎${user.cName }</h5></li>
		      			<li><a href="${pageContext.request.contextPath }/UserServlet?action=logout">退出登录</a></li>
		      		</c:if>
		      	
		        	
		      	</ul>
   			</div>
 			</div>
 			
	</nav>

</body>
</html>